const userInfoName = 'hm_shopping_userInfo' // 用户信息
const historyList = 'hm_shopping_historyList' // 搜索记录

// 获取用户token
export const getUserInfo = () => {
  const obj = {
    token: '',
    userId: ''
  }
  const userInfo = localStorage.getItem(userInfoName)

  return userInfo ? JSON.parse(userInfo) : obj
}

// 设置用户token
export const setUserInfo = (obj) => {
  localStorage.setItem(userInfoName, JSON.stringify(obj))
}

// 删除用户token
export const removeUserInfo = () => {
  localStorage.removeItem(userInfoName)
}

// 获取搜索记录
export const getHistoryList = () => {
  const list = localStorage.getItem(historyList)
  return list ? JSON.parse(list) : []
}

// 设置搜索记录
export const setHistoryList = (list) => {
  localStorage.setItem(historyList, JSON.stringify(list))
}
